


$(function(){
	$('.c1 li').prop('contenteditable','true');
	$('.c1 .del,.c1 .edit,.c1 .id').prop('contenteditable','false');
	$('.c3 .cid').blur(function(){
		var len = $(this).text().length;
		if(len == 4){
			$('.c3 .pid').text($(this).text().substr(0,2));
		}else if(len == 2){
			$('.c3 .pid').text('');
		}else{
			$(this).text('');
		}
	});
	
	//增加分类事件
	$('#kpclass').on('click','.c3 .add,.c1 .edit,.c1 .del',
		function(){
			var cidLen = $(this).siblings('.cid').text().length;
			//alert(cidLen);
			var pidLen = $(this).siblings('.pid').text().length;
			var nameLen = $.trim($(this).siblings('.cname').text()).length;
			//alert(nameLen);
			if(cidLen != 2 && cidLen != 4 || nameLen < 1){
				alert('不合法!');
				return false;
			}
			var uid = $(this).siblings('.id').text();
			var ucid = $(this).siblings('.cid').text();
			var upid = $(this).siblings('.pid').text()
			var ucname = $.trim($(this).siblings('.cname').text());
			var ueve = 0;
			var uclick = $(this).attr('class');
			if(uclick == 'add'){
				ueve = 1;
			}else if(uclick == 'edit'){
				ueve = 2;
			}else if(uclick == 'del'){
				ueve = 3;
			}
			
			
			$.post("ajax/islogin.php",{
				eve: ueve//1增加分类,2修改,3.删除
				,id: uid
				,cid: ucid
				,pid: upid
				,cname: ucname
			},function(data, textStatus, reXML){
				if(data == 1){
					alert('操作成功!');
					//window.location.reload();//当前页面重新加载
					$("#kpclass").load("kpclass.php #kpclass>*",""); //局部刷新
				}else{
					alert(data);
				}
				
				//$('#kpclass>.c1').load('kpclass.php',$('#kpclass>.c1'));
				//$(".c1").load(location.href+" .c1>*",""); //局部刷新
			},"text");
		}
	);

	
});



